package com.sky.controller.admin;

import com.sky.QueryByPage.CategoryQueryByPage;
import com.sky.dto.CategoryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import com.sky.vo.CategoryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Api(tags = "分类管理相关接口")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result getByPage( CategoryQueryByPage cqbp){
        PageResult categoryVOS =  categoryService.getByPage(cqbp);
        return Result.success(categoryVOS);
    }

    @PutMapping
    @ApiOperation("修改分类")
    public Result update(@RequestBody CategoryDTO categoryDTO){
        categoryService.update(categoryDTO);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    @ApiOperation("启用/禁用")
    public Result enable(@PathVariable Integer status,@RequestParam Integer id){
        categoryService.enable(status,id);
        return Result.success();
    }

    @PostMapping
    @ApiOperation("新增分类")
    public Result add(@RequestBody CategoryDTO categoryDTO){
        categoryService.add(categoryDTO);
        return Result.success();
    }

    @DeleteMapping
    @ApiOperation("根据id删除分类")
    public Result delete(@RequestParam Integer id){
        categoryService.delete(id);
        return Result.success();
    }

    @GetMapping("/list")
    public Result getlist(@RequestParam Integer type){
        List<CategoryVO> getlist = categoryService.getlist(type);
        return Result.success(getlist);
    }

}
